#include <windows.h>
#include <stdio.h>
#include "utils.h"

void error_exit(const char* op)
{
    wchar_t buff[1024];
    DWORD dw = GetLastError();
    swprintf(buff, 1024, L"%S failed. Error %d", op, dw);
    MessageBox(NULL, buff, L"Error", MB_OK);
    ExitProcess(1);
}

int a2w(const char* a, wchar_t* w, int max_size)
{
    int out_size;
    int in_size = 0;

    if (NULL == a)
    {
        *w = 0;
        return 0;
    }

    in_size = strlen(a) + 1;
    if (in_size > max_size)
    {
        in_size = max_size;
    }

    out_size = MultiByteToWideChar(CP_ACP, 0, a, in_size, w, max_size);

    w[out_size] = 0;

    if (out_size == 0)
    {
        return -1;
    }

    return 0;
}
